var core    = require("core")
,   db      = core.db
,   schema  = db.schema
,   send    = core.send;

var POST    = function(req, res, next){
    var body        = req.body
    ,   pid         = body.pid
    ,   platformId  = body.platformId
    ,   secret      = body.secret
    ,   key         = body.key
    ,   url         = body.url
    ,   msg         = body.msg
    ,   admin       = body.admin
    ,   number      = body.number;

    var query = {
        platformId  : platformId
    }
    ,   update = {
        platformId  : platformId,
        secret      : secret,
        key         : key,
        url         : url,
        msg         : msg,
        admin       : admin,
        number      : number
    }
    ,   options = {
        new         : true
    };
    schema.Platform.findOneAndUpdate(query, update, options, function(err, docs){
        if(err || !docs)
            SEND = new send(200000);
        else{
            docs = JSON.parse(JSON.stringify(docs));
            delete docs._id;
            delete docs.__v;
            req.app.platform.item[platformId] = docs;
            SEND = new send(0);
            SEND.docs = docs;
        };
        res.send(SEND);
    });

};

module.exports = POST;
